package
{
	import flash.utils.getDefinitionByName;
	import flash.text.TextFormat;
	import flash.text.TextField;
	import flash.display.MovieClip;

	public class NinjaGUI
	{
		public var levelnameMC:MovieClip;
		public var input_txtbox:MovieClip;
		public var input_txtbox2:MovieClip;
		public var timeMC:MovieClip;
		public var playerDisplayTime:Number;
		public var textmenuMC:TextField;
		public var menuMC:MovieClip;
		public var textlineMC:MovieClip;

		public function NinjaGUI()
		{
			this.levelnameMC = Main.getInstance().gfx.CreateSprite("guiLevelNameMC", NinjaGraphicsSystem.LAYER_GUI);
			this.levelnameMC.x = 396;
			this.levelnameMC.y = 580;
			this.levelnameMC.visible = false;
			//
			var depth:Number = Main.getInstance().gfx.GetNextDepth_Front();
			this.input_txtbox = new (getDefinitionByName("inputBox") as Class)() as MovieClip;
			this.input_txtbox.name = "inputBox" + depth;
			this.input_txtbox.x = 450;
			this.input_txtbox.y = 50;
			this.input_txtbox.tabEnabled = false;
			this.input_txtbox.backgroundColor = 16316664 /* 0xF8F8F8 */;
			this.input_txtbox.visible = false;
			Main.getInstance().addChildAtDepth(this.input_txtbox, depth);
			//
			var depth = Main.getInstance().gfx.GetNextDepth_Front();
			this.input_txtbox2 = new (getDefinitionByName("inputBox2") as Class)() as MovieClip;
			this.input_txtbox2.name = "inputBox" + depth;
			this.input_txtbox2.x = 450;
			this.input_txtbox2.y = 200;
			this.input_txtbox2.tabEnabled = false;
			this.input_txtbox2.backgroundColor = 16316664 /* 0xF8F8F8 */;
			this.input_txtbox2.visible = false;
			Main.getInstance().addChildAtDepth(this.input_txtbox2, depth);
			//
			this.timeMC = Main.getInstance().gfx.CreateSprite("timeIndicator", NinjaGraphicsSystem.LAYER_GUI);
			this.timeMC.x = Main.getInstance().APP_TILE_SCALE * 2;
			this.timeMC.y = Main.getInstance().APP_TILE_SCALE;
			this.timeMC.bar.scaleX = 0;
			this.timeMC.txtbox.y = -8;
			this.playerDisplayTime = 0;
			//
			var depth = Main.getInstance().gfx.GetNextDepth_Front();
			this.textmenuMC = new TextField();
			this.textmenuMC.name = "ninjaGUITextField";
			this.textmenuMC.x = this.textmenuMC.y = 0;
			this.textmenuMC.width = 545;
			this.textmenuMC.height = 290;
			this.textmenuMC.multiline = true;
			this.textmenuMC.wordWrap = true;
			this.textmenuMC.selectable = false;
			this.textmenuMC.border = false;
			var _local2 = new TextFormat();
			_local2["color"] = 0;
			_local2.font = "_typewriter";
			_local2.size = 12;
			_local2.align = "left";
			this.textmenuMC.setTextFormat(_local2);
			this.textmenuMC.x = 44;
			this.textmenuMC.y = 300;
			Main.getInstance().addChildAtDepth(this.textmenuMC, depth);
			//
			this.menuMC = Main.getInstance().gfx.CreateSprite("MenuMC", NinjaGraphicsSystem.LAYER_GUI);
			this.menuMC.x = 0;
			this.menuMC.y = 0;
			this.menuMC.gotoAndStop("blank");
			this.menuMC.visible = false;
			//
			this.textlineMC = Main.getInstance().gfx.CreateSprite("guiTextLineMC", NinjaGraphicsSystem.LAYER_GUI);
			this.textlineMC.x = 44;
			this.textlineMC.y = 240;
			this.textlineMC.visible = false;
			this.InitData();
		}

		public function SetPlayerTime(t):void
		{
			this.playerDisplayTime = t;
		}

		public function ResetPlayerTime():void
		{
			this.playerDisplayTime = 0;
		}

		public function FillPlayerTime(cur, maxT):void
		{
			var dt = (cur - this.playerDisplayTime);
			this.playerDisplayTime = this.playerDisplayTime + (0.05 * dt);
			var ratio = (this.playerDisplayTime / (maxT * 2));
			this.timeMC.bar.scaleX = Math.min(700, 600 * ratio);
			this.timeMC.bar.gotoAndStop(Math.max(1, Math.min(101 - Math.floor(100 * ratio), 101)));
			var _local2 = this.playerDisplayTime * Main.getInstance().APP_GAMETIME_TICKLEN;
			var _local3 = Math.floor(_local2 / 1000);
			_local2 = Math.floor(_local2 - (_local3 * 1000));
			this.timeMC.txtbox.txt = (("" + _local3) + ".") + _local2;
			this.timeMC.txtbox.x = Math.floor(this.timeMC.bar.scaleX) + 1;
		}

		public function DrawPlayerTime(cur, maxT):void
		{
			var amt = (cur / maxT);
			var _local3 = 1 - amt;
			_local3 = Math.min(1, Math.max(0.05, _local3 * _local3));
			var dt = (cur - this.playerDisplayTime);
			this.playerDisplayTime = this.playerDisplayTime + (_local3 * dt);
			var ratio = (this.playerDisplayTime / (maxT * 2));
			this.timeMC.bar.scaleX = Math.min(700, 600 * ratio);
			this.timeMC.bar.gotoAndStop(Math.max(1, Math.min(101 - Math.floor(100 * ratio), 101)));
			var _local2 = this.playerDisplayTime * Main.getInstance().APP_GAMETIME_TICKLEN;
			var s = Math.floor(_local2 / 1000);
			_local2 = Math.floor(_local2 - (s * 1000));
			this.timeMC.txtbox.txt = (("" + s) + ".") + _local2;
			this.timeMC.txtbox.x = Math.floor(this.timeMC.bar.scaleX) + 1;
		}

		public function DrawLevelName(str):void
		{
			this.levelnameMC.visible = true;
			this.levelnameMC.txt = str;
		}

		public function ShowInGame():void
		{
			this.levelnameMC.visible = true;
			this.timeMC.visible = true;
		}

		public function HideInGame():void
		{
			this.levelnameMC.visible = false;
			this.timeMC.visible = false;
		}

		public function HideAll():void
		{
			this.menuMC.visible = false;
			this.textmenuMC.visible = false;
			this.textlineMC.visible = false;
			this.HideTxt();
		}

		public function ShowAll():void
		{
			this.menuMC.visible = true;
			this.textmenuMC.visible = true;
			this.textlineMC.visible = true;
		}

		public function HideMenu():void
		{
			this.menuMC.visible = false;
		}

		public function ShowMenu():void
		{
			this.menuMC.visible = true;
		}

		public function HideTextMenu():void
		{
			this.textmenuMC.visible = false;
			this.textlineMC.visible = false;
		}

		public function ShowTextMenu():void
		{
			this.textmenuMC.visible = true;
			this.textlineMC.visible = true;
		}

		public function DisplayRawText(str):void
		{
			this.textmenuMC.visible = true;
			this.textmenuMC.text = str;
		}

		public function DisplayTextBar(GUI_ID):void
		{
			this.textlineMC.visible = true;
			this.textlineMC.txt = this.guiList[GUI_ID];
		}

		public function AppendToTextBar(str):void
		{
			this.textlineMC.txt = this.textlineMC.txt + str;
		}

		public function Display(GUI_ID):void
		{
			var _local2 = GUI_ID;
			if (this.guiList[_local2] == null)
			{
			}
			else if (NinjaGUI.GUI_LAST_STRING_INDEX < _local2)
			{
				var frm = this.guiList[_local2];
				this.DisplayFrame(frm);
			}
			else
			{
				var _local3 = this.guiList[_local2];
				var temp = typeof(_local3);
				if (temp == "string")
				{
					this.DisplayString(_local3);
				}
				else
				{
					this.DisplayList(_local3);
				}
			}
		}

		public function GetCurrentMC():MovieClip
		{
			return(this.menuMC);
		}

		public function DisplayFrame(frm):void
		{
			this.textmenuMC.visible = false;
			this.textlineMC.visible = false;
			this.menuMC.visible = true;
			this.menuMC.gotoAndStop(frm);
		}

		public function DisplayString(str):void
		{
			this.menuMC.visible = false;
			this.textmenuMC.visible = false;
			this.textlineMC.visible = true;
			this.textlineMC.txt = str;
		}

		public function DisplayList(strList):void
		{
			var _local3 = strList;
			this.menuMC.visible = false;
			this.textlineMC.visible = false;
			this.textmenuMC.visible = true;
			this.textmenuMC.text = "";
			var _local1 = 0;
			while (_local1 < _local3.length)
			{
				this.textmenuMC.text = this.textmenuMC.text + _local3[_local1];
				this.textmenuMC.text = this.textmenuMC.text + "\n";
				_local1++;
			}
		}

		//
		public static const TXTBOX_TOP:int = 0;
		public static const TXTBOX_BOTTOM:int = 1;

		public function GetTxt(boxNum)
		{
			var _local1 = boxNum;
			this.ShowTxt();
			if (_local1 == NinjaGUI.TXTBOX_TOP)
			{
				return(this.input_txtbox.txt);
			}
			else if (_local1 == NinjaGUI.TXTBOX_BOTTOM)
			{
				return(this.input_txtbox2.txt);
				return(undefined);
			}
			return(undefined);
		}

		public function SetTxt(boxNum, str):void
		{
			var _local1 = boxNum;
			this.ShowTxt();
			if (_local1 == NinjaGUI.TXTBOX_TOP)
			{
				this.input_txtbox.txt = str;
			}
			else if (_local1 == NinjaGUI.TXTBOX_BOTTOM)
			{
				this.input_txtbox2.txt = str;
				return;
			}
		}

		public function HideTxt():void
		{
			this.input_txtbox.visible = (this.input_txtbox2.visible = false);
		}

		public function ShowTxt():void
		{
			this.input_txtbox.visible = (this.input_txtbox2.visible = true);
		}

		//
		public static const GUI_LOADINGAPP:int = 0;
		public static const GUI_CONFIRMQUIT:int = 1;
		public static const GUI_LOADINGLEVEL:int = 2;
		public static const GUI_PRELEVEL:int = 3;
		public static const GUI_PAUSE:int = 4;
		public static const GUI_RETRYLEVEL:int = 5;
		public static const GUI_POSTLEVEL:int = 6;
		public static const GUI_DEBUGMENU:int = 7;
		public static const GUI_RESETTINGLEVEL:int = 8;
		public static const GUI_TEMP_EDITOR:int = 9;
		public static const GUI_TILE_EDITOR:int = 10;
		public static const GUI_OBJ_EDITOR:int = 11;
		public static const GUI_INGAMEDEMO:int = 12;
		public static const GUI_PASSEDEPISODE:int = 13;
		public static const GUI_RETRYLEVEL_SUICIDE:int = 14;
		public static const GUI_BEATGAME:int = 15;
		public static const GUI_GAMEOVER:int = 16;
		public static const GUI_KEYCONFIG:int = 17;
		public static const GUI_LAST_STRING_INDEX:int = 17;
		public static const GUI_MAINMENU:int = 18;
		public static const GUI_CONTINUE:int = 19;
		public static const GUI_HELP:int = 20;
		public static const GUI_STORY:int = 21;
		public static const GUI_GOODBYE1:int = 22;
		public static const GUI_GOODBYE2:int = 23;
		public static const GUI_GOODBYE3:int = 24;
		public static const GUI_GOODBYE4:int = 25;
		public static const GUI_VICTORY:int = 26;
		public static const GUI_PLAYMENU:int = 27;
		public static const GUI_CONFIGURE:int = 28;
		public static const GUI_DEFEAT:int = 29;
		//
		public var guiList:Object;

		public function InitData():void
		{
			this.guiList = new Object();
			this.guiList[NinjaGUI.GUI_LOADINGAPP] = "loading app..";
			this.guiList[NinjaGUI.GUI_CONFIRMQUIT] = "really quit? (y/n)";
			this.guiList[NinjaGUI.GUI_LOADINGLEVEL] = "loading level... (please wait)";
			this.guiList[NinjaGUI.GUI_PRELEVEL] = "level loaded; press [spacebar] to begin";
			this.guiList[NinjaGUI.GUI_PAUSE] = "[game paused]   P: unpause   Q: quit to mainmenu";
			this.guiList[NinjaGUI.GUI_RETRYLEVEL] = "ouch... press [spacebar] to try again, [R] to watch replay";
			this.guiList[NinjaGUI.GUI_POSTLEVEL] = "level complete! press [spacebar] to load next level.";
			this.guiList[NinjaGUI.GUI_RESETTINGLEVEL] = "resetting level... (please wait)";
			this.guiList[NinjaGUI.GUI_INGAMEDEMO] = "instant replay... press [spacebar] to try again.";
			this.guiList[NinjaGUI.GUI_RETRYLEVEL_SUICIDE] = "harsh, guy! press [spacebar] to try again.";
			this.guiList[NinjaGUI.GUI_BEATGAME] = "you have achieved transcendence!!!  ..[spacebar] for main menu";
			this.guiList[NinjaGUI.GUI_GAMEOVER] = "..you ran out of time. GAME OVER. press [spacebar] for main menu";
			this.guiList[NinjaGUI.GUI_PASSEDEPISODE] = "";
			this.guiList[NinjaGUI.GUI_KEYCONFIG] = "press your desired key; [Q] to abort";
			this.guiList[NinjaGUI.GUI_HELP] = "help_menu";
			this.guiList[NinjaGUI.GUI_STORY] = "story_menu";
			this.guiList[NinjaGUI.GUI_MAINMENU] = "main_menu";
			this.guiList[NinjaGUI.GUI_CONTINUE] = "continue_menu";
			this.guiList[NinjaGUI.GUI_GOODBYE1] = "credits1";
			this.guiList[NinjaGUI.GUI_GOODBYE2] = "credits2";
			this.guiList[NinjaGUI.GUI_GOODBYE3] = "credits3";
			this.guiList[NinjaGUI.GUI_GOODBYE4] = "credits4";
			this.guiList[NinjaGUI.GUI_VICTORY] = "beatgame";
			this.guiList[NinjaGUI.GUI_DEFEAT] = "gameover";
			this.guiList[NinjaGUI.GUI_PLAYMENU] = "play_menu";
			this.guiList[NinjaGUI.GUI_CONFIGURE] = "config_menu";
			var temp2 = new Array();
			temp2.push("");
			temp2.push("**** DEBUG MENU ****");
			temp2.push("[M]: mainmenu");
			temp2.push("[L]: load level (from textbox)");
			temp2.push("[S]: save level (to clipboard)");
			temp2.push("[J]: load empty map");
			temp2.push("[E]: edit level");
			temp2.push("[P]: continue playing level");
			temp2.push("[R]: reset objects");
			temp2.push("---");
			temp2.push("[1]: begin recording demo");
			temp2.push("[2]: stop recording demo");
			temp2.push("[Q]: begin demo playback (WARNING: resets objects)");
			temp2.push("[W]: end demo playback");
			temp2.push("[3]: load demo (from textbox)");
			temp2.push("[4]: save demo (to clipboard)");
			this.guiList[NinjaGUI.GUI_DEBUGMENU] = temp2;
			temp2 = null;
			var _local2 = new Array();
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("");
			_local2.push("+++++++++++++< Ned >+++++++++++++");
			_local2.push("   [insert]:  obj editor");
			_local2.push("   [delete]:  tile editor");
			_local2.push("     [PGDN]:  save data (to txtbox)");
			_local2.push("     [PGUP]:  load data (from txtbox)");
			_local2.push("------------------------");
			_local2.push("[~] or [\\]:  back to debug menu");
			this.guiList[NinjaGUI.GUI_TEMP_EDITOR] = _local2;
			var temp4 = new Array();
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("");
			temp4.push("---(editing tiles)---");
			temp4.push("[insert]: obj editor");
			temp4.push("  [home]: edit menu");
			this.guiList[NinjaGUI.GUI_TILE_EDITOR] = temp4;
			temp4 = null;
			var _local3 = new Array();
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("");
			_local3.push("--(editing objects)---");
			_local3.push("[backspace + click]: delete object");
			_local3.push("[delete]: tile editor");
			_local3.push("  [home]: edit menu");
			this.guiList[NinjaGUI.GUI_OBJ_EDITOR] = _local3;
		}
	}
}